package com.jjwxc.jwjskandriod.readActivity.dao;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import com.jjwxc.jwjskandriod.readActivity.bean.BookChapterBean;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import java.util.List;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.

/**
 * DAO for table "BOOK_CHAPTER_BEAN".
 */
public class BookChapterBeanDao extends AbstractDao<BookChapterBean, String> {

    public static final String TABLENAME = "BOOK_CHAPTER_BEAN";

    /**
     * Properties of entity BookChapterBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, String.class, "id", true, "ID");
        public final static Property Title = new Property(1, String.class, "title", false, "TITLE");
        public final static Property TaskName = new Property(2, String.class, "taskName", false, "TASK_NAME");
        public final static Property Unreadble = new Property(3, boolean.class, "unreadble", false, "UNREADBLE");
        public final static Property BookId = new Property(4, String.class, "bookId", false, "BOOK_ID");
        public final static Property Start = new Property(5, long.class, "start", false, "START");
        public final static Property End = new Property(6, long.class, "end", false, "END");
        public final static Property Position = new Property(7, long.class, "position", false, "POSITION");
        public final static Property Vip = new Property(8, boolean.class, "vip", false, "VIP");
        public final static Property MonthSubscribe = new Property(9, boolean.class, "monthSubscribe", false, "MONTH_SUBSCRIBE");
        public final static Property HasAuth = new Property(10, boolean.class, "hasAuth", false, "HAS_AUTH");
        public final static Property price = new Property(11, String.class, "price", false, "PRICE");
        public final static Property juan = new Property(12, String.class, "juan", false, "JUAN");
    }

    private Query<BookChapterBean> downloadTaskBean_BookChapterListQuery;
    private Query<BookChapterBean> collBookBean_BookChapterListQuery;

    public BookChapterBeanDao(DaoConfig config) {
        super(config);
    }

    public BookChapterBeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /**
     * Creates the underlying database table.
     */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists ? "IF NOT EXISTS " : "";
        db.execSQL("CREATE TABLE " + constraint + "\"BOOK_CHAPTER_BEAN\" (" + //
                "\"ID\" TEXT PRIMARY KEY NOT NULL ," + // 0: id
                "\"TITLE\" TEXT," + // 1: title
                "\"TASK_NAME\" TEXT," + // 2: taskName
                "\"UNREADBLE\" INTEGER NOT NULL ," + // 3: unreadble
                "\"BOOK_ID\" TEXT," + // 4: bookId
                "\"START\" INTEGER NOT NULL ," + // 5: start
                "\"END\" INTEGER NOT NULL ," + // 6: end
                "\"POSITION\" INTEGER NOT NULL ," +// 7: position
                "\"VIP\" INTEGER NOT NULL ," +// 8: vip
                "\"MONTH_SUBSCRIBE\" INTEGER NOT NULL ," +// 9: monthSubscribe
                "\"HAS_AUTH\" INTEGER NOT NULL , " +// 10: hasAuth
                "\"PRICE\"  TEXT, " +// 11: price
                "\"JUAN\" TEXT " +// 12: juan
                ");");
        // Add Indexes
        db.execSQL("CREATE INDEX " + constraint + "IDX_BOOK_CHAPTER_BEAN_BOOK_ID ON \"BOOK_CHAPTER_BEAN\"" +
                " (\"BOOK_ID\" ASC);");
    }

    /**
     * Drops the underlying database table.
     */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"BOOK_CHAPTER_BEAN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, BookChapterBean entity) {
        stmt.clearBindings();

        String id = entity.getId();
        if (id != null) {
            stmt.bindString(1, id);
        }

        String title = entity.getTitle();
        if (title != null) {
            stmt.bindString(2, title);
        }

        String taskName = entity.getTaskName();
        if (taskName != null) {
            stmt.bindString(3, taskName);
        }
        stmt.bindLong(4, entity.getUnreadble() ? 1L : 0L);

        String bookId = entity.getBookId();
        if (bookId != null) {
            stmt.bindString(5, bookId);
        }
        stmt.bindLong(6, entity.getStart());
        stmt.bindLong(7, entity.getEnd());
        stmt.bindLong(8, entity.getPosition());
        stmt.bindLong(9, entity.isVip() ? 1L : 0L);
        stmt.bindLong(10, entity.isMonthSubscribe() ? 1L : 0L);
        stmt.bindLong(11, entity.isHasAuth() ? 1L : 0L);
        String price = entity.getPrice();
        if (price != null) {
            stmt.bindString(12, price);
        }
        String juan = entity.getJuan();
        if (juan != null) {
            stmt.bindString(13, juan);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, BookChapterBean entity) {
        stmt.clearBindings();

        String id = entity.getId();
        if (id != null) {
            stmt.bindString(1, id);
        }

        String title = entity.getTitle();
        if (title != null) {
            stmt.bindString(2, title);
        }

        String taskName = entity.getTaskName();
        if (taskName != null) {
            stmt.bindString(3, taskName);
        }
        stmt.bindLong(4, entity.getUnreadble() ? 1L : 0L);

        String bookId = entity.getBookId();
        if (bookId != null) {
            stmt.bindString(5, bookId);
        }
        stmt.bindLong(6, entity.getStart());
        stmt.bindLong(7, entity.getEnd());
        stmt.bindLong(8, entity.getPosition());
        stmt.bindLong(9, entity.isVip() ? 1L : 0L);
        stmt.bindLong(10, entity.isMonthSubscribe() ? 1L : 0L);
        stmt.bindLong(11, entity.isHasAuth() ? 1L : 0L);
        String price = entity.getPrice();
        if (price != null) {
            stmt.bindString(12, price);
        }
        String juan = entity.getJuan();
        if (juan != null) {
            stmt.bindString(13, juan);
        }
    }

    @Override
    public String readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1);
    }

    @Override
    public BookChapterBean readEntity(Cursor cursor, int offset) {
        BookChapterBean entity = new BookChapterBean( //
                cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // id
                cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // title
                cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // taskName
                cursor.getShort(offset + 3) != 0, // unreadble
                cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // bookId
                cursor.getLong(offset + 5), // start
                cursor.getLong(offset + 6), // end
                cursor.getLong(offset + 7),// position
                cursor.getShort(offset + 8) != 0, //vip
                cursor.getShort(offset + 9) != 0, //monthSubscribe
                cursor.getShort(offset + 10) != 0,//hasAuth
                cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11),//price
                cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12)//juan
        );
        return entity;
    }

    @Override
    public void readEntity(Cursor cursor, BookChapterBean entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
        entity.setTitle(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setTaskName(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setUnreadble(cursor.getShort(offset + 3) != 0);
        entity.setBookId(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setStart(cursor.getLong(offset + 5));
        entity.setEnd(cursor.getLong(offset + 6));
        entity.setPosition(cursor.getLong(offset + 7));
        entity.setVip(cursor.getLong(offset + 8) != 0);
        entity.setMonthSubscribe(cursor.getLong(offset + 9) != 0);
        entity.setHasAuth(cursor.getLong(offset + 10) != 0);
        entity.setPrice(cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11));
        entity.setJuan(cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12));
    }

    @Override
    protected final String updateKeyAfterInsert(BookChapterBean entity, long rowId) {
        return entity.getId();
    }

    @Override
    public String getKey(BookChapterBean entity) {
        if (entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(BookChapterBean entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }

    /**
     * Internal query to resolve the "bookChapterList" to-many relationship of DownloadTaskBean.
     */
    public List<BookChapterBean> _queryDownloadTaskBean_BookChapterList(String taskName) {
        synchronized (this) {
            if (downloadTaskBean_BookChapterListQuery == null) {
                QueryBuilder<BookChapterBean> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.TaskName.eq(null));
                downloadTaskBean_BookChapterListQuery = queryBuilder.build();
            }
        }
        Query<BookChapterBean> query = downloadTaskBean_BookChapterListQuery.forCurrentThread();
        query.setParameter(0, taskName);
        return query.list();
    }

    /**
     * Internal query to resolve the "bookChapterList" to-many relationship of CollBookBean.
     */
    public List<BookChapterBean> _queryCollBookBean_BookChapterList(String bookId) {
        synchronized (this) {
            if (collBookBean_BookChapterListQuery == null) {
                QueryBuilder<BookChapterBean> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.BookId.eq(null));
                collBookBean_BookChapterListQuery = queryBuilder.build();
            }
        }
        Query<BookChapterBean> query = collBookBean_BookChapterListQuery.forCurrentThread();
        query.setParameter(0, bookId);
        return query.list();
    }

}
